package com.ibeetl.admin.api.web;

import com.ibeetl.admin.api.entity.Travel_map_path;
import com.ibeetl.admin.api.service.RouteService;
import com.ibeetl.admin.core.web.JsonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@Tag(
        name = "TravelMapPathController"
        )
public class TravelMapPathController {
    private final Log log = LogFactory.getLog(this.getClass());
    private static final String MODEL = "/api/travel_map_path";

    @Resource
    private RouteService routeService;

    @Operation(
            summary = "增加景点路线点坐标"
    )
    @PostMapping(MODEL + "/add.json")
    @CrossOrigin
    public JsonResult<Travel_map_path> add(Travel_map_path route) {
        route.setCreateDt(new Date());
        if(routeService.save(route)){
            Long pathId = routeService.queryNewIdByAttractionId(route.getAttractionId());
            route.setPathId(pathId);
            return JsonResult.success(route);
        }else {
            return JsonResult.failMessage("新增失败！");
        }

    }
    @Operation(
            summary = "批量增加景点路线点坐标"
    )
    @PostMapping(MODEL + "/batchAdd.json")
    @CrossOrigin
    public JsonResult<Travel_map_path> batchAdd(@RequestBody List<Travel_map_path> routes) {
        if(routes != null && routes.size()>0){
            for(Travel_map_path route : routes){
                route.setCreateDt(new Date());
                routeService.save(route);
            }
        }
        return JsonResult.success();

    }
    @Operation(
            summary = "修改景点路线点坐标"
    )
    @PostMapping(MODEL + "/update.json")
    @CrossOrigin
    public JsonResult<Travel_map_path> update(Travel_map_path route) {
        route.setUpdateDt(new Date());
        route.setCreateDt(new Date());
        routeService.update(route);
        return JsonResult.success(route);
    }
    @Operation(
            summary = "删除景点路线点坐标"
    )
    @PostMapping(MODEL + "/del.json")
    @CrossOrigin
    public JsonResult<Travel_map_path> del(Long pathId) {
        routeService.del(pathId,3);
        return JsonResult.success();
    }
    @Operation(
            summary = "查询景点路线点坐标"
    )
    @PostMapping(MODEL + "/queryByPathId.json")
    @CrossOrigin
    public JsonResult<Travel_map_path> queryByPathId(Long pathId) {
        Travel_map_path route  = routeService.queryById(pathId);
        return JsonResult.success(route);
    }
    @Operation(
            summary = "根据景点路线ID查询景点路线点坐标"
    )
    @PostMapping(MODEL + "/queryByAttractionId.json")
    @CrossOrigin
    public JsonResult<List> queryByAttractionId(@RequestParam(required = false) Long attractionId) {
        List<Travel_map_path> list =  routeService.queryByAttractionId(attractionId);
        return JsonResult.success(list);
    }
}
